package com.atguigu.tingshu.album.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseAttribute;
import com.atguigu.tingshu.model.album.BaseCategory1;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * /api/album/category/findAttribute/1
 */

@Tag(name = "分类管理")
@RestController
@RequestMapping(value="/api/album/category")
@SuppressWarnings({"all"})
public class BaseCategoryApiController {
	
	@Autowired
	private BaseCategoryService baseCategoryService;


	/**
	 * 查询所有的一级分类信息
	 * @return
	 */
	@Operation(summary = "查询所有的一级分类信息")
	@GetMapping("/findAllCategory1")
	public Result<List<BaseCategory1>> findAllCategory1(){
		List<BaseCategory1> baseCategory1List=baseCategoryService.findAllCategory1();
		return Result.ok(baseCategory1List);
	}

	/**
	 * 根据一级分类Id 获取全部数据
	 * @param category1Id
	 * @return
	 */
	@GetMapping("/findTopBaseCategory3/{category1Id}")
	public Result<List<BaseCategory3>> findTopBaseCategory3(@PathVariable Long category1Id){
		// 调用service方法
		List<BaseCategory3>  baseCategory3List= baseCategoryService.findTopBaseCategory3(category1Id);
		//返回数据
		return Result.ok(baseCategory3List);
	}

	/**
	 * 根据一级分类Id 获取全部数据
	 * @param category1Id
	 * @return
	 */
	@Operation(summary = "根据一级分类id获取全部分类信息")
	@GetMapping("/getBaseCategoryList/{category1Id}")
	public  Result<JSONObject> getBaseCategoryList(@PathVariable("category1Id") Long category1Id){
		JSONObject categoey=baseCategoryService.getCategory(category1Id);
		return Result.ok(categoey);
	}

	/**
	 * 获取分类列表
	 * @return
	 */
	@Operation(summary = "获取分类列表")
	@GetMapping("getBaseCategoryList")
	public Result  getCategoryList(){
		List<JSONObject> categoryList=baseCategoryService.getCategoryList();
		return  Result.ok(categoryList);
	}

	/**
	 * 获取分类属性值
	 * @param category1Id
	 * @return
	 */
	@Operation(summary = "获取分类属性值")
	@GetMapping("/findAttribute/{category1Id}")
	public Result findAttribute(@PathVariable(value = "category1Id") Long category1Id){
		return Result.ok(baseCategoryService.findAttribute(category1Id));
	}

	@Operation(summary = "获取三级分类")
	@GetMapping("/getCategoryView/{category3Id}")
	public Result<BaseCategoryView> getCategoryView(@PathVariable(value = "category3Id") Long category3Id){
		BaseCategoryView baseCategoryView=baseCategoryService.findCategory(category3Id);
		return Result.ok(baseCategoryView);
	}

}

